<template>
  <el-card class="box-card-component" style="margin-left:8px;">
    <div slot="header" class="box-card-header">
      <img src="https://wpimg.wallstcn.com/e7d23d71-cf19-4b90-a1cc-f56af8c0903d.png">
    </div>
    <div style="position:relative;">
      <pan-thumb :image="avatar" class="panThumb" />
      <div ref="qrcode" class="qrcode-wrapper" />
      <mallki class-name="mallki-text" text="admin" />
      <div style="padding-top:35px;" class="progress-item" />
      <el-descriptions class="margin-top" :column="1">
        <el-descriptions-item label="IP位置">{{ pos || '未知' }}</el-descriptions-item>
        <el-descriptions-item label="登录时间">{{ loginTime }}</el-descriptions-item>
        <el-descriptions-item label="用户状态">
          <el-tag size="small" type="success">在线</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="在线时长">
          <el-tag size="small">{{ duration }} 分钟</el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </div>
  </el-card>
</template>

<script>
// 引入二维码生成依赖
import QRCode from 'qrcodejs2'
import { mapGetters } from 'vuex'
import PanThumb from '@/components/PanThumb'
import Mallki from '@/components/TextHoverEffect/Mallki'
import moment from 'moment'

export default {
  components: { PanThumb, Mallki },

  filters: {
    statusFilter(status) {
      const statusMap = {
        success: 'success',
        pending: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      statisticsData: {
        article_count: 1024,
        pageviews_count: 1024
      },
      loginTime: 0,
      timer: null,
      duration: 0,
      qrcode: null
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'avatar',
      'roles',
      'city',
      'province'
    ]),
    pos() {
      return this.province.slice(0, -1) + this.city
    }
  },
  created() {
    this.loginTime = moment(Number(localStorage.getItem('loginTime'))).locale('zh-cn').format('lll')
  },
  mounted() {
    this.timer = setInterval(() => {
      this.duration = parseInt((new Date() - localStorage.getItem('loginTime')) / 60000)
    }, 1000)
    this.creatQrCode()
  },
  beforeDestroy() {
    clearInterval(this.timer)
    this.timer = null
  },
  methods: {
    creatQrCode() {
      const text = 'EA156A2C16EB8F24FE98EC6A36B3CB23229DFDB192C100F49828704FED25E43E'
      this.qrcode = new QRCode(this.$refs.qrcode, {
        text, // 二维码内容字符串
        width: 60 * 4, // 图像宽度
        height: 60 * 4, // 图像高度
        colorDark: '#000000', // 二维码前景色
        colorLight: '#ffffff', // 二维码背景色
        correctLevel: QRCode.CorrectLevel.H // 容错级别
      })
      this.qrcode._el.title = ''
    }
  }
}
</script>

<style lang="scss" >
.box-card-component{
  .el-card__header {
    padding: 0px!important;
  }

}
</style>
<style lang="scss" scoped>

.box-card-component {
  .box-card-header {
    position: relative;
    height: 220px;
    img {
      width: 100%;
      height: 100%;
      transition: all 0.2s linear;
      &:hover {
        transform: scale(1.1, 1.1);
        filter: contrast(130%);
      }
    }
  }
  .mallki-text {
    position: absolute;
    top: 0px;
    right: 0px;
    font-size: 20px;
    font-weight: bold;
  }
  .panThumb {
    z-index: 100;
    height: 70px!important;
    width: 70px!important;
    position: absolute!important;
    top: -45px;
    left: 0px;
    border: 5px solid #ffffff;
    background-color: #fff;
    margin: auto;
    box-shadow: none!important;
    ::v-deep .pan-info {
      box-shadow: none!important;
    }
  }
  ::v-deep .qrcode-wrapper {
    position: absolute;
    bottom: 10px;
    right: 10px;
    padding: 5px;
    width: 60px;
    height: 60px;
    box-shadow: rgba(0, 0, 0, 0.05) 0px 0px 0px 1px;
    img, canvas {
      width:100%;
      height:100%;
    }
  }
  @media only screen and (max-width: 1000px){
    .mallki-text{
      display: none;
    }
  }
}

</style>
